
import React, { useState, useEffect } from 'react';
import { Button, DatePicker, Form, Input, Select } from 'antd';
import * as service from "../../../api/index"


 interface  props{

}
const onFinish = async (values:any) => {
    console.log('Success:', values);
    //在这里拿到数据去发添加数据的请求
    var res = await service.Zixun_add({ state: "待回复", department: values.department, type: values.type, headline: values.headline, content: values.content, name: values.name, phone: values.phone,  time1:values.time[0].$y+"-"+(values.time[0].$M+1)+"-"+values.time[0].$D, time2:values.time[1].$y+"-"+(values.time[1].$M+1)+"-"+values.time[1].$D})

    console.log(res)
};

const onFinishFailed = (errorInfo:any) => {
    console.log('Failed:', errorInfo);
};

const { RangePicker } = DatePicker;




function Zixunadd(props:props) {
    const [form] = Form.useForm();
    const { Option } = Select;

    const onGenderChange = (value:any) => {
        switch (value) {
            case 'male':
                form.setFieldsValue({ note: 'Hi, man!' });
                break;
            case 'female':
                form.setFieldsValue({ note: 'Hi, lady!' });
                break;
            case 'other':
                form.setFieldsValue({ note: 'Hi there!' });
                break;
            default:
        }
    };
    const list = async () => {
        var res = await service.Zixun_list()
        console.log(res)
    }
    useEffect(() => {
        list()
    }, [])
    return (
        <div>

            <Form
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                style={{ maxWidth: 600 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item
                    label="受理部门"
                    name="department"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item name="type" label="类型" rules={[{ required: true }]}>
                    <Select
                        placeholder="请选择"
                        onChange={onGenderChange}
                        allowClear
                    >
                        <Option value="办件">办件</Option>
                        <Option value="办件">账户</Option>
                    </Select>
                </Form.Item>
                <Form.Item
                    label="咨询标题"
                    name="headline"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="咨询内容"
                    name="content"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="联系人名字"
                    name="name"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="电话"
                    name="phone"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item name="time" label="提交时间-截止时间">
                    <RangePicker />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        添加
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
}

export default Zixunadd;